// 正则库
export const reg = {
  // 手机号码验证
  phone: /^1[3456789][0-9]{9}$/,
  // 6-16位数字 字母 字符
  password: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z!@#$%^&*?]{6,16}$/,
  // 6位支付密码
  pay: /^\d{6}$/,
  // 验证码 code
  code: /^\d{4}$/,
  // 账号  字母数字混合
  account: /[^a-zA-Z0-9]/g,
  //身份证号码
  idCard: /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
  // 邮箱正则
  email: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
  // 网址
  url: /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\/])+$/,
  // 日期格式 yyyy-MM-dd
  date: /^(\d{4})-(\d{2})-(\d{2})$/,
  // 时间格式 hh:mm:ss
  time: /^(\d{2}):(\d{2}):(\d{2})$/,
  // 日期时间格式 yyyy-MM-dd hh:mm:ss
  datetime: /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/,
  // 分数  0-100
  score: /^(0|[1-9]\d?|100)$/,
}
// 角色规则
export const roleList = [
  {id: 0, name: "学员",},
  {id: 1, name: "老师",},
  {id: 2, name: "管理员",}
]

export const PhatList = [
  {label: "首页", key: "/main/home", permission: 0, notAllowed: 2},
  {
    label: "教务管理", key: "/main/academicAffairs", permission: 1, notAllowed: 2, children: [
      {label: "学科管理", key: "/main/academicAffairs/subject", permission: 2, notAllowed: 2,},
      {label: "班级管理", key: "/main/academicAffairs/class", permission: 2, notAllowed: 2,},
      {label: "项目类别管理", key: "/main/academicAffairs/projectType", permission: 1, notAllowed: 2,}
    ],
  },
  {
    label: "用户管理", key: "/main/user", permission: 1, notAllowed: 2, children: [
      {label: "用户列表", key: "/main/user/userList", permission: 1, notAllowed: 2,},
      {label: "添加用户", key: "/main/user/addUser", permission: 2, notAllowed: 2,},
      {label: "用户分析", key: "/main/user/userData", permission: 2, notAllowed: 2,}
    ],
  },
  {
    label: "项目管理", key: "/main/project", permission: 0, notAllowed: 2, children: [
      {label: "我的项目", key: "/main/project/myProject", permission: 0, notAllowed: 0,},
      {label: "提交项目", key: "/main/project/upProject", permission: 0, notAllowed: 0,},
      {label: "项目评分", key: "/main/project/projectScore", permission: 1, notAllowed: 2,},
      {label: "项目数据", key: "/main/project/projectData", permission: 1, notAllowed: 2,}
    ],
  },
  {
    label: "公告管理", key: "/main/announcement", permission: 2, notAllowed: 2, children: [
      {label: "公告列表", key: "/main/announcement/announcementList", permission: 2, notAllowed: 2,},
      {label: "发布公告", key: "/main/announcement/addAnnouncement", permission: 2, notAllowed: 2,}
    ],
  },
  {
    label: "论面试", key: "/main/interview", permission: 0, notAllowed: 2, children: [
      {label: "言论广场", key: "/main/interview/interviewList", permission: 0, notAllowed: 2,},
      {label: "发布言论", key: "/main/interview/addInterview", permission: 0, notAllowed: 2,},
      {label: "我的言论", key: "/main/interview/myInterview", permission: 0, notAllowed: 2,},
    ],
  }
]

export const loaderComponent = (lazyComponent, attemptsLeft = 3, interval = 1000) => {
  return new Promise((resolve, reject) => {
    lazyComponent().then(resolve).catch((error) => {
      setTimeout(() => {
        if (attemptsLeft > 0) {
          loaderComponent(lazyComponent, attemptsLeft - 1, interval).then(resolve).catch(reject)
        } else {
          reject(error)
        }
      }, interval)
    })
  })
}